package com.skywaregroup.arenal;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class ValidPubRoleLogicValidator implements
		ConstraintValidator<ValidPubRoleLogic, Card> {

	@Override
	public void initialize(ValidPubRoleLogic constraintAnnotation) {
	}

	@Override
	public boolean isValid(Card card, ConstraintValidatorContext context) {
		if (card == null) {
			return true;
		}
		
		//Publisher is holder itself and no other holder. In any other case
		//practiceHolder should be non null value
		return (card.publisherRole != 0 ^ card.practiceHolder == null);

	}
}